module executor.friend.client.DealApplyContactExecutor;

import msgtrans;
import message.Constants;
import cache.UserStatusManager;
import hunt.logging;
import google.protobuf;
import message.MsgDefine;
import cache.ChatIdMap;
import client.GateServerClient;
import std.array;
import std.conv : to;



@TransportClient(LogicClientName)
class DealApplyContactExecutor : AbstractExecutor!(DealApplyContactExecutor){

  @MessageId(MESSAGE.CMD_DEAL_FRIEND_RES)
  void dealApplyContact(TransportContext ctx, MessageBuffer buffer)
  {
    AddContact addFriend = new AddContact;
    buffer.data.fromProtobuf!AddContact(addFriend);

    //if (to!int(addFriend.chatId) % g_msgServerSize == g_msgServerIndex)
    //{
    //  string[string] userMap;
    //  userMap[addFriend.toId] = addFriend.toId;
    //  userMap[addFriend.user.id] = addFriend.user.id;
    //  ChatIdMap.getInstance().createChat(addFriend.chatId,userMap);
    //}

    if (UserStatusManager.getInstance().getUserStatus(addFriend.toId)) //online
    {
      TransportSession[ulong] contexts = GateServerClient.getInstance.getAllClient();
      foreach(TransportSession c ; contexts)
      {
        c.send(new MessageBuffer(MESSAGE.CMD_DEAL_FRIEND_RES,addFriend.toProtobuf.array));
      }
    }
  }
}

